import json

from Crypto.Cipher import AES
import base64

def pad(data):
    """PKCS5 padding (block size 16 for AES)."""
    pad_len = 16 - (len(data) % 16)
    return data + bytes([pad_len] * pad_len)

def is_empty(s):
    return s is None or s == ""

def a(str_key, str2):
    if is_empty(str_key) or is_empty(str2):
        return ""

    try:
        # 1. 密钥必须为16字节，可截断或补齐
        key_bytes = str_key.encode()[:16]     # 如果超过16字节自动截断
        key_bytes = key_bytes.ljust(16, b'\0') # 不足16字节自动补齐0

        # 2. 明文PKCS5填充
        data = pad(str2.encode())

        # 3. AES-ECB加密
        cipher = AES.new(key_bytes, AES.MODE_ECB)
        encrypted = cipher.encrypt(data)

        # 4. Base64编码
        return base64.b64encode(encrypted).decode()
    except Exception as e:
        print(e)
        return ""
data={"bd_return_size":"71.5791","bd_net_type":"wifi","bd_return_time":"0.358","bd_dtime":"1754536861","list":[{"local_ip":"","url":"https://iphone.myzaker.com/zaker/interaction.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.23","dtime":"1.75453683E9"},{"local_ip":"","url":"https://iphone.myzaker.com/zaker/app_style.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_flag\u003d9f0369ff51876206a9b5dd33b6d91686\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_time\u003d1754536856\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal\u0026sign_arg\u003dapp_style|_appid,_nudid,_udid,_uid,_version","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.26","dtime":"1.75453683E9"},{"local_ip":"","url":"https://iphone.myzaker.com/zaker/ar_data/ar_list.php?_appid\u003dAndroidPhone\u0026_brand\u003dRedmi\u0026_clicode\u003ddrkjeSEfcYDX1teOXihrCj2XzcFRNfVX8%2BYz4c8F97ou09PFuxwXRz5MiGDDPUNGhem0wpj6%2FrZjDz2db1S7FvanFsXVXzuSqDN0%2F9H5fXQboq5tdRLZNTtTWglt14Ow2up6UUUAOroimS1HlUPRnt%2FCQ4I%2BuQaYbMO3tBgfzppDreyPYJ3gJetESX4Iz9g%2F\u0026_dev\u003d39\u0026_mcode\u003d782ECE9C\u0026_only_read\u003dN\u0026_os\u003d13_23013RK75C\u0026_os_name\u003d23013RK75C\u0026_udid\u003d1fb67af59b5699a6\u0026_v\u003d9.1.5\u0026_version\u003d9.08\u0026appType\u003dnormal","net_type":"wifi","req_type":"local","e_type":"2","return_time":"3.363","dtime":"1.75453683E9"}]}
ddata=json.dumps(data)
# 用法
if __name__ == "__main__":
    result = a("amJKJsirodlsd129", ddata)
    print(result)